package com.ktgj.flight.common.ruili;

import com.ktgj.flight.common.ruili.drdomain.BookingContact;
import com.ktgj.flight.domain.InterfaceEntity.MoFlightSearchRequest;
import com.ktgj.flight.domain.InterfaceEntity.MoQueryOrderRequest;
import com.ktgj.flight.domain.InterfaceEntity.MoQueryOrderResponse;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 瑞丽接口测试
 */
public class TestDr {
    public static void main(String[] args) {
        _DR rd = new _DR();
        /**
         * 航空查询
         * */
        MoFlightSearchRequest moRequest = new MoFlightSearchRequest();
        moRequest.TripType = 1;
        moRequest.GoSearchWhere.DepDate = "2022-09-15";
        moRequest.GoSearchWhere.OrgAirport = "KMG";
        moRequest.GoSearchWhere.DstAirport = "TSN";
        /*moRequest.GoSearchWhere.FlightNo = "DR9997T";
        moRequest.GoSearchWhere.Cabin = "M";*/
        moRequest.GoSearchWhere.carrier = "DR";

        rd._FlightSearch(moRequest);


        /*moRequest.TripType=2;
        moRequest.BackSearchWhere.DepDate = "2021-10-20";
        moRequest.BackSearchWhere.OrgAirport = "LUM";
        moRequest.BackSearchWhere.DstAirport = "KMG";
        moRequest.BackSearchWhere.FlightNo = "DR6501";
        moRequest.BackSearchWhere.Cabin = "M";
        moRequest.BackSearchWhere.carrier = "DR";*//*

        MoFlightSearchResponse moFlightSearchResponse = null;
        try {
           moFlightSearchResponse = rd._FlightSearch(moRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }*/

        /**
         * 舱位验价
         * */
        /*BookingSegment bookingSegment=new BookingSegment();
        bookingSegment.QueryResultId=moFlightSearchResponse.Piid;
        bookingSegment.FlightNo=moRequest.GoSearchWhere.FlightNo;
        bookingSegment.Departure=moRequest.GoSearchWhere.OrgAirport;
        bookingSegment.Arrival=moRequest.GoSearchWhere.DstAirport;
        bookingSegment.SeatCode=moRequest.GoSearchWhere.Cabin;
        bookingSegment.RouteIndex=1;
        bookingSegment.ProductCode=moFlightSearchResponse.ProviderCode;*/

       /* MoFlightCheckRequest moFlightCheckRequest =new MoFlightCheckRequest();
        moFlightCheckRequest.FlightNo = "DR9997T";
        moFlightCheckRequest.PolicyID = "01222aea-4d9e-4825-9c69-272b6b1c1ef6";
        moFlightCheckRequest.OrgAirport = "LUM";
        moFlightCheckRequest.DstAirport ="KMG";
        moFlightCheckRequest.Cabin = "M";
        moFlightCheckRequest.ProductType ="FULLFARE";



        try {
            MoFlightCheckResponse moFlightCheckResponse = rd._FlightCheck(moFlightCheckRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
*/


        /**
         * 瑞丽航班预订
         * */

/*

        MoCreateOrderRequest moRequest = new MoCreateOrderRequest();
        moRequest.PolicyID = "85723295-8182-40cb-9830-c3fd377918a3";
        MoSegment moSegment = new MoSegment();
        moSegment.FlightNo= "DR6559";
        moSegment.OrgAirport = "KMG";
        moSegment.DstAirport = "LUM";
        moSegment.ProductType = "FULLFARE";
        moSegment.DepDate=convertToDate("2022-03-31 07:50:00","yyyy-MM-dd HH:mm:ss");
        moSegment.ArrDate=convertToDate("2022-03-31 09:10:00","yyyy-MM-dd HH:mm:ss");
        moSegment.Cabin="K";
        moRequest.ListGoSegment.add(moSegment);


        MoPassenger moPassenger = new MoPassenger();
        moPassenger.PassengerName ="测试王亚杰";
        moPassenger.PassengerType =1;
        moPassenger.IDType=1;
        moPassenger.IDNO="620521199710260030";
        moPassenger.Sex=false;
        moPassenger.PassengerMobile="17610641000";
        moPassenger.Birthday=convertToDate("1997-10-26","yyyy-MM-dd");
        moPassenger.TicketAmount = new BigDecimal(1000);

        moRequest.ListMoPassenger.add(moPassenger);

        MoContacts contacts= new MoContacts();
        contacts.ContactName="测试王亚杰";
        contacts.ContactPreNum="86";
        contacts.ContactMobile="15037102578";
        contacts.Address="北京";

        moRequest.Contacts =contacts;

        moRequest.IsNeedPost = true;

        moRequest.TripType = 1;

        try {
            MoCreateOrderResponse moCreateOrderResponse=rd._OrderCreate(moRequest);
        }catch (Exception e){
            e.printStackTrace();
        }
*/

/*        BookingContact bookingContact = new BookingContact();
        System.out.println(bookingContact);

       //订单基本信息查询
       List<String> lstOrderId = new ArrayList<>();
       List<HashMap<String, MoQueryOrderResponse>> lstOrders = new ArrayList<>();
       lstOrderId.add("2963511");
       lstOrderId.add("2960598");
        lstOrderId.add("2960840");
        lstOrderId.add("2962103");
        lstOrderId.add("2963033");
        lstOrderId.add("2963357");
        lstOrderId.add("2963455");
        lstOrderId.add("2963492");
        lstOrderId.add("2963511");
//        lstOrderId.add("2912802");
        for (String orderId: lstOrderId)
        {
            MoQueryOrderRequest request = new MoQueryOrderRequest();
            request.OrderID = orderId;
            try
            {
                MoQueryOrderResponse response = rd._QueryOrderInfo(request);
                HashMap<String,MoQueryOrderResponse> mOrder = new HashMap<>();
                mOrder.put(orderId,response);
                lstOrders.add(mOrder);
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        System.out.println(lstOrders);*/

        //订单明细查询
       /* MoQueryOrderRequest request =new MoQueryOrderRequest();
        request.OrderID = "2963511";
        request.BigPnr = "3015447";
        try {
            rd._QueryFastOrderInfo(request);
        } catch (IOException e) {
            e.printStackTrace();
        }*/


        //订单支付
        /*MoOrderPayRequest request = new MoOrderPayRequest();
        request.OrderID="2963511";
        request.PayAmount = new BigDecimal("960.00");
        request.RequestType = EnumHelper.RequestType.瑞丽;
        request.BigPnr="3015447";
        try {
            rd._OrderPay(request);
        } catch (Exception e) {
            e.printStackTrace();
        }*/


        //出票
        /*MoAutoPayOutTicketRequest request=new MoAutoPayOutTicketRequest();
        request.OrderID="202202250002872959";
        try {
            rd._AutoPayOutTicket(request);
        } catch (Exception e) {
            e.printStackTrace();
        }*/


        //退票
        /*MoOrderRefundRequest refundRequest=new MoOrderRefundRequest();
        refundRequest.OrderID="2963511";
        try {
            rd._OrderRefund(refundRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }*/


        /*MoRescheduleSearchRequest rescheduleSearchRequest=new MoRescheduleSearchRequest();
        rescheduleSearchRequest.RescheduleFlightDepartDate=convertToDate("2022-04-01 07:50:00","yyyy-MM-dd HH:mm:ss");
        rescheduleSearchRequest.OrderID="2963511";



        rd._SearchChangeDateFlightInfo(rescheduleSearchRequest);*/


       /* MoOrderRefundCaltRequest refundCaltRequest=new MoOrderRefundCaltRequest();
        refundCaltRequest.OutOrderID="2963511";

        rd._OrderRefundCalt(refundCaltRequest,true);*/


        //退票
//        MoOrderRefundRequest request=new MoOrderRefundRequest();
//        request.OrderID="2963511";
//
//        List<MoPassenger> passengers=new ArrayList<>();
//        MoPassenger passenger=new MoPassenger();
//        passenger.PassengerName="测试王亚杰";
//        passengers.add(passenger);
//
//        request.ListMoPassenger=passengers;
//        request.RefundType=1; //自愿退票
//
//        rd._OrderRefund(request);


    }


    public static Date convertToDate(String str, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        Date date = null;
        if (str != null) {
            try {
                date = sdf.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return date;
    }

}
